package com.jzz.eletuanbackend.controller;

import com.alibaba.fastjson.JSON;
import com.jzz.eletuanbackend.service.DelivererService;
import com.jzz.eletuanbackend.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.PostRemove;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/deliverer")
public class DelivererController {

    @Autowired
    private DelivererService delivererService;

    @PostMapping("/position/update")
    public void updatePosition(@RequestParam("user_id") Long userId,
                               @RequestParam("longitude") Double longitude,
                               @RequestParam("latitude") Double latitude) {
        delivererService.updatePosition(userId, longitude, latitude);
    }

    @RequestMapping("/position/get")
    public Msg getPosition(@RequestParam("user_id") Long id) {
        return delivererService.getPosition(id);
    }

    @PostMapping("/order/take")
    public Msg takeOrder(@RequestParam("user_id") Long userId, @RequestParam("orderId") Long orderId) {
        return delivererService.takeOrder(userId, orderId);
    }

    @PostMapping("/order/arrive")
    public Msg arriveOrder(@RequestParam("orderId") Long orderId) {
        return delivererService.arriveOrder(orderId);
    }

    @PostMapping("/order/deliver")
    public Msg deliverOrder(@RequestParam("orderId") Long orderId) {
        return delivererService.deliverOrder(orderId);
    }

    @PostMapping("/order/receive")
    public Msg receiveOrder(@RequestParam("orderId") Long orderId) {
        return delivererService.receiveOrder(orderId);
    }

    @RequestMapping("/order/all")
    public Msg getAllOrders(@RequestParam("user_id") Long userId) {
        return delivererService.getAllOrders(userId);
    }

    @RequestMapping("/order/get")
    public Msg getOrder(@RequestParam("orderId") Long id) {
        return delivererService.getOrder(id);
    }

    @RequestMapping("/order/available")
    public Msg availableOrders() {
        return delivererService.availableOrders();
    }
}
